package com.hzh.cusviewdemo.Activity;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.LinearSmoothScroller;
import androidx.recyclerview.widget.RecyclerView;

import android.app.Notification;
import android.app.PendingIntent;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import com.hzh.cusviewdemo.Adapter.TopAdapter;
import com.hzh.cusviewdemo.R;

import java.util.ArrayList;
import java.util.List;

public class RecyclerActivity extends AppCompatActivity {

    private RecyclerView ar_list;
    private TextView ar_jump;

    private LinearLayoutManager mManager; // 布局管理器
    private TopAdapter topAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_recycler);

        ar_list = findViewById(R.id.ar_list);
        ar_jump = findViewById(R.id.ar_jump);

        // 初始化数据
        List<String> datas = new ArrayList<>();
        for (int i = 0; i < 100; i++) {
            datas.add("pos---" + i);
        }

        mManager = new LinearLayoutManager(this);
        ar_list.setLayoutManager(mManager);
        ar_list.setAdapter(new TopAdapter(datas));


        // 随机跳转
        ar_jump.setOnClickListener(v -> {
            int position = (int) (Math.random() * 100);
            LinearSmoothScroller smoothScroller = new LinearSmoothScroller(this);
            smoothScroller.setTargetPosition(20);
            mManager.startSmoothScroll(smoothScroller);
            Toast.makeText(this, "已滑动到：" + position, Toast.LENGTH_SHORT).show();
        });


    }
}